﻿using System.ComponentModel;
using ZeroSum.App.Datas;
using ZeroSumZSA.Api.Apis;
using ZeroSumZSA.Application.ApplicationServices.Menus;
using ZeroSumZSA.Application.ApplicationServices.Menus.Dto.In;
using ZeroSumZSA.Application.ApplicationServices.Menus.Dto.Out;
using ZeroSumZSA.Application.ApplicationServices.Menus.Dto.Query;

namespace ZeroSumZSA.Api.Controllers;

/// <summary>
///     菜单
/// </summary>
[Description("管理-菜单管理")]
public class MenuController : ApiController
{
    private readonly ILogger<RoleController> _logger;
    private readonly IMenuApplicationService _service;

    /// <summary>
    ///     构造函数
    /// </summary>
    /// <param name="service"></param>
    /// <param name="logger"></param>
    public MenuController(IMenuApplicationService service, ILogger<RoleController> logger)
    {
        _service = service;
        _logger = logger;
    }

    /// <summary>
    ///     增加系统菜单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Add([FromBody] AddMenuDto input)
    {
        await _service.Add(input);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     删除系统菜单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Delete([FromBody] DeleteMenuDto input)
    {
        await _service.Delete(input);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     更新系统菜单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse> Edit([FromBody] EditMenuDto input)
    {
        await _service.UpdateAsync(input);
        return ApiResponse.Ok();
    }

    /// <summary>
    ///     获取系统菜单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<ApiResponse<DetailMenuDto>> Detail([FromBody] DetailMenuQuery input)
    {
        return ApiResponse<DetailMenuDto>.Of(await _service.Detail(input));
    }
}